home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
NetNews Offline 2
/
NetNews Offline Volume 2.iso
/
news
/
comp
/
std
/
c
/
268
< prev
next >
Wrap
Text File
|
1996-08-06
|
3KB
|
68 lines
Newsgroups: comp.lang.c,comp.std.c
Path: blackbush.xlink.net!slsv6bt!slsv6bt!kanze
From: kanze@lts.sel.alcatel.de (James Kanze US/ESC 60/3/141 #40763)
Subject: Re: Integral conversion e.t.c. (was: Re: Hungarian notation)
In-Reply-To: Lawrence Kirby's message of Tue, 30 Jan 96 00:13:24 GMT
Message-ID: <KANZE.96Feb1143506@slsvewt.lts.sel.alcatel.de>
Sender: news@lts.sel.alcatel.de
Organization: SEL
References: <30C40F77.53B5@swsbbs.com> <SPENCER.96Jan22113215@zorgon.ERA.COM>
<KANZE.96Jan29201312@slsvewt.lts.sel.alcatel.de>
<822960804snz@genesis.demon.co.uk>
Date: 01 Feb 1996 13:35:06 GMT
In article <822960804snz@genesis.demon.co.uk> Lawrence Kirby
<fred@genesis.demon.co.uk> writes:
|> In article <KANZE.96Jan29201312@slsvewt.lts.sel.alcatel.de>
|> kanze@lts.sel.alcatel.de "James Kanze US/ESC 60/3/141 #40763" writes:
|> >Again, I think that one should make the distinction (at least in
|> >comp.lang.c) between undefined undefined by the standard, and really
|> >undefined.
|> I don't think you'll find it easy to make such a distinction.
I have one example which actually occurs in real code. I need to
declare a buffer (array of unsigned char) with sufficient size *AND*
correct alignment for an arbitrary type. I normally do this with:
union
{
unsigned char data[ n * sizeof( T ) ] ;
union MaxAlign dummyForAlignment ;
} buffer ;
where MaxAlign is defined (in a header file) as:
union MaxAlign
{
long l ;
unsigned long ul ;
double d ;
long double ld ;
void* pv ;
struct X* ps ;
void (*pf)() ;
} ;
In practice, I have yet to hear of a machine where the above union
wouldn't guarantee an alignment sufficient for any possible type, but
as far as I can tell, this is not guaranteed by the standard. (And of
course, if it ever does fail, I'll just add whatever new type is
necessary to make it work.)
I consider the code which uses this construct well defined and
completely portable in real life, but it is undefined according to the
standard.
I'll admit that there are very few such cases, and most of them go in
the other direction: code that is well defined and legal according to
the standard, but will cause trouble on a large class of machines.
--
James Kanze Tel.: (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs-Bourgeois, F-67000 Strasbourg, France
Conseils, Θtudes et rΘalisations en logiciel orientΘ objet --
-- A la recherche d'une activitΘ dans une region francophone